{extend name="base/base" /}
{block name="body"}

    <div class="layui-row">
        <form id="main_form" class="layui-form layui-form-pane" action="" method="post" lay-filter="main-form-group">
            <!-- ==================================  隐藏区  ================================== -->
            <!--隐藏域-->

            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-tab-item layui-show">

                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">用户组名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="title" value="{$info['title']}"
                                           lay-verify="required" lay-verType="tips"
                                           autocomplete="off"
                                           class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">用户组名称</div>
                            </div>
                        </div>



                        <div class="layui-form-item">
                            <label class="layui-form-label">选择区域</label>
                            <div class="layui-input-inline">
                                <select name="module" lay-filter="aihao">
                                    <option value=""></option>
                                    <option value="admin" {if($info['module']=="admin")}  selected {/if}>后台权限</option>
                                    <option value="home" {if($info['module']=="home")}  selected {/if}>前台权限</option>
                                </select>
                            </div>
                            <div class="layui-form-mid layui-word-aux">作用</div>
                        </div>


                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">描述</label>
                            <div class="layui-input-block">
                            <textarea name="description" placeholder="请输入内容" class="layui-textarea"
                                      style="height: 100px;">{$info['description']}</textarea>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
            <input type="hidden" name="id" value="{$info['id']}"/>
            <!-- 按钮区 -->
            <div class="layui-form-item layui-layout-admin" style="display: none">
                <div class="layui-input-block">

                    <div class="layui-footer" style="left: 0;">
                        <button id="form_save" lay-filter="form_save" class="layui-btn"
                                lay-submit="">
                            保存
                        </button>
                        <button id="form_reset" type="button" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </div>
        </form>
    </div>


    <script src="/static/stv/admin/layuiadmin/layui/layui.js"></script>
    <script src="/static/stv/admin/js/admin.common.js"></script>
    <script>

        var save_url = '{:url('admin/authmanager/edit')}';
        layui.config({
            base: '/static/stv/admin/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'laydate'], function(){
            var $ = layui.$
                ,admin = layui.admin
                ,element = layui.element
                ,layer = layui.layer
                ,laydate = layui.laydate
                ,form = layui.form;

            form.render(null, 'component-form-group');

            laydate.render({
                elem: '#LAY-component-form-group-date'
            });

            /* 自定义验证规则 */
            form.verify({
                title: function(value){
                    if(value.length < 5){
                        return '标题至少得5个字符啊';
                    }
                }
                ,pass: [/(.+){6,12}$/, '密码必须6到12位']
                ,content: function(value){
                    layedit.sync(editIndex);
                }
            });

            /* 监听指定开关 */
            form.on('switch(component-form-switchTest)', function(data){
                layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                    offset: '6px'
                });
                layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
            });

            /* 监听提交 */
            form.on('submit(form_save)', function(data){
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                $.post(save_url, data.field, function (res) {
                    try {
                        if(res.status==200) {
                            //重新刷新父窗口的数据区
                            parent.layui.table.reload('test-table-reload'); //重载表格
                            parent.layer.close(index); //再执行关闭
                        }else{
                            layer.msg(res.message);
                        }
                    } catch (e) {
                        layer.msg("异常");
                    }

                }, "json");

                return false;
            });
        });

        layui.use('upload', function(){
            var upload = layui.upload;
            upload.render({
                elem: '#upload_img_btn'
                ,url: '/public/upload/pic' //上传接口
                ,done: function(res, index, upload){
                    //获取当前触发上传的元素，一般用于 elem 绑定 class 的情况，注意：此乃 layui 2.1.0 新增
                    var item = this.item;
                    if (res.code == 0) {
                        item.closest(".layui-form-item").find("#upload_img_url").val(res.data.src);
                    } else {
                        layer.msg(res.message);
                    }
                }
            });
        });
    </script>
{/block}
